package com.sf.wisdomkg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sf.wisdomkg.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Administrator on 2017/8/29.
 */
public class JianHuRenListViewAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<HashMap<String, String>> list;

    public JianHuRenListViewAdapter(Context context, ArrayList<HashMap<String,String>> data_list) {
        this.context = context;
        this.list = data_list;

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    public View getView(int position, View convertView, ViewGroup arg2) {
        // TODO Auto-generated method stub
        LayoutInflater inflater = LayoutInflater.from(context);
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.jianhuren_list_item,null);
            viewHolder.jian_hu_name= (TextView) convertView.findViewById(R.id.jian_hu_name);
            viewHolder.jianhu_sex= (TextView) convertView.findViewById(R.id.jianhu_sex);
            viewHolder.jinahu_age= (TextView) convertView.findViewById(R.id.jinahu_age);
            viewHolder.jianhu_phone = (TextView) convertView.findViewById(R.id.jianhu_phone);
            viewHolder.jianhu_job = (TextView) convertView.findViewById(R.id.jianhu_job);
            viewHolder.jianhu_address = (TextView) convertView.findViewById(R.id.jianhu_address);
            viewHolder.head_img = (ImageView)convertView.findViewById(R.id.head_img);

            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

//        hashMap.put("id",jsonObjectSon.optString("id"));
//        hashMap.put("name",jsonObjectSon.optString("name"));
//        hashMap.put("age",jsonObjectSon.optString("age"));
//        hashMap.put("sex",jsonObjectSon.optString("sex"));
//        hashMap.put("phone",jsonObjectSon.optString("mother"));
//        hashMap.put("job",jsonObjectSon.optString("img"));
//        hashMap.put("address",jsonObjectSon.toString());
//
        viewHolder.jian_hu_name.setText(list.get(position).get("name"));
        if (list.get(position).get("sex").equals("0")){
            viewHolder.jianhu_sex.setText("男");
            viewHolder.head_img.setImageResource(R.mipmap.boy_head_icon_parent);
        }else {
            viewHolder.jianhu_sex.setText("女");
            viewHolder.head_img.setImageResource(R.mipmap.girl_head_icon_parent);
        }
        viewHolder.jianhu_phone.setText(list.get(position).get("phone"));
        viewHolder.jianhu_job.setText(list.get(position).get("job"));
        viewHolder.jianhu_address.setText(list.get(position).get("address"));
        viewHolder.jinahu_age.setText(list.get(position).get("age"));
//        Glide.with(context).load(list.get(position).get("image")).into(viewHolder.new_right);
        return convertView;
    }
    public class ViewHolder{
        TextView jian_hu_name,jianhu_sex,jinahu_age,jianhu_phone,jianhu_job,jianhu_address;
        ImageView head_img;

    }
}
